<template>
  <!--输入框-->
  <div style="height: 100%">
  <div class="input">
    <el-row>
      <el-upload class="upload"
        action="api/common/upload"
        :on-success="successUpload"
        :headers="headers"
        :showFileList="false"
        :data="{use:'NOTICE',problemId:0}"
      >
    <el-button type="info" size="large">上传图片</el-button>
      </el-upload>
    </el-row>
  </div>

<!--    新增公告-->
  <div class="exam-list">
    <el-table
        :data="notice"
        border
        style="width: 100%;">
      <el-table-column
          label="序号"
          width="60"
          align="center">
        <template #default="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column
          prop="path"
          label="公告图片"
          width="200"
          align="center">
        <template v-slot="scope">
          <el-image
              style="width: 100px; height: 100px"
              :src="'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column
          prop="name"
          label="公告名"
          width="230"
          align="center">
      </el-table-column>
      <el-table-column
          prop="createdAt"
          label="创建时间"
          width="200"
          align="center">
      </el-table-column>
      <el-table-column
          prop="updatedAt"
          label="修改时间"
          width="200"
          align="center">
      </el-table-column>
      <el-table-column label="操作" >
        <template #default="scope">
          <el-button
              size="small"
              type="danger"
              @click="updateNotice">修改公告
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>

  </div>
</template>

<script >
import  API from '@/api/manage'
var token =localStorage.getItem('token')
export default {
  data(){
    return{
      notice:[],
      addNoticeForm:{
        name:''
      },
      headers:{token: token},
    }
  },
  mounted() {
    this.listNotice()
  },
  methods:{
    successUpload(res){
      console.log(res)
      if(res.success) {
        this.$message.success('图片上传成功')
      }
      this.listNotice()
    },
    listNotice(){
      let token = localStorage.getItem('token')
      let param ={}
      API.queryNotice(param,token).then(res=>{
        if(res.data.code==='0'){
          this.notice=res.data.content
          for(let i=0;i< this.notice.length;i++){
            let x = this.notice[i].name.indexOf('.')
            this.notice[i].name=this.notice[i].name.slice(0,x)
          }
          console.log(this.notice)
        }
      }).catch(error=>{
        console.log(error)
      })
    },
    updateNotice(){

    }
  },


}






</script>

<style scoped>
 .upload{
   margin-left: 10px;
   margin-bottom: 10px;
 }
 .dialog-footer{
   margin-left: 150px;
 }


</style>
